<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>前后端分离登录页面</title>
    <script src="/js/jquery.min.js"></script>
    <script src="/js/jquery.cookie.min.js"></script>
</head>
<body>
<form action="">
    <input type="text" id="username">
    <input type="password" id="password">
    <input type="submit" value="登录" id="loginBtn">
</form>
<script>
    $(function () {
        $("#loginBtn").click(function () {
            var _csrf = $.cookie('XSRF-TOKEN');
            var form_data = {"username":$("#username").val(),"password":$("#password").val(),"_csrf":_csrf}
            // $.post("/doLogin",form_data,function (data) {
            //     debugger
            //     alert(data)
            // })
            $.ajax({
                url:"/doLogin",
                type:"POST",
                dataType: "text",//预期服务器返回的数据类型
                data:form_data,
                success:function (result) {
                    alert(result)
                },
                error:function () {
                    alert("失败哦")
                }
            })
            return false;
        })
    })
</script>
</body>
</html>